package com.example.chinesenation.ExceptionHandler;

import com.example.chinesenation.Exception.AuthenException;
import com.example.chinesenation.Response.ResultType;
import com.example.chinesenation.Response.ServerResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author sakuraFallingDown
 * @version 1.0
 * @date 2021/1/11 15:18
 */
@ControllerAdvice
public class AuthenExceptionHandler {//全局异常处理

    private final Logger logger= LoggerFactory.getLogger(getClass());
    @ResponseBody
    @ExceptionHandler(AuthenException.class)
    public ServerResponse<String> handler(AuthenException authenException){
        logger.error(authenException.getResultType().getMsg());
        return ServerResponse.createErrorsResponse(authenException.getResultType());
    }
}
